home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / ORBIT_SO / EASYDIAL.H < prev    next >
Text File  |  1992-07-19  |  5KB  |  121 lines

  1. /* Include files for my easy dialog handler */
  2. /* Copyright 1987                            */
  3. /* David Palmer                             */
  4. /* Mail code 220-47                            */
  5. /* California Institute Of Technology         */
  6. /* Duplication, modification, and examination allowed on a    */
  7. /* non-commercial basis only.  Commercial use prohibited    */
  8. /* without prior written agreement with the author.  (This    */
  9. /* includes sale by for-profit companies, and use as an        */
  10. /* inducement to buy something.)                            */
  11.  
  12. /************************Description*************************/
  13. /*
  14.  *    EasyDialog.h is a package to allow data-driven dialog
  15.  *    boxes.  This package is incomplete, badly documented,
  16.  *    and subject to revision.  On the other hand, it does have
  17.  *    flaws.
  18.  *    The main entry point in this package is "EasyDialog()"
  19.  *  Its definition is:
  20.  *        int EasyDialog(id, pedi)
  21.  *        int id;
  22.  *        EDITEM *pedi;
  23.  *  It returns the itemnumber of the final button pushed.  (A button
  24.  *    is final if it has no associated procedure, or if the associated
  25.  *    procedure returns a non-zero value.  More about this later)
  26.  *  The id is the resource number of the dialog, pedi points to
  27.  *    an array of EDITEMs.  (ED stands, of course, for EasyDialog)
  28.  *    The definition of EDITEM is included in this file.  The elements of
  29.  *    the structure are:
  30.  *
  31.  *    int nitems;
  32.  *    int firstitem;
  33.  *      These are the number of items in a set, and the itemnumber
  34.  *        (dialog item number) of the first in the set.  For radio buttons,
  35.  *        a set defines a group of which only one may be turned on at one
  36.  *        time.  For other item types, the elements of a set are independant
  37.  *    enum EDItemType itemtype;
  38.  *        This element determines the behaviour of the item.  If it does
  39.  *        not correspond to the actual type of the dialog item, you may
  40.  *        have trouble.  edchars, edstrings, edints, and edfloats require an
  41.  *        item of editable text, the remainder are self-explanatory
  42.  *        except for edlast, which is an itemtype indicating the end
  43.  *        of the array of EDITEMs.  (You must have one of these, or
  44.  *        dire things will happen.)
  45.  *    void *pvalue;
  46.  *        A pointer to the value or set of values controlled by the
  47.  *        dialog items in the EDITEM.  For radio buttons, the value
  48.  *        is set to the number of the button pressed, starting from
  49.  *        one for the first of the set.  For strings, it points to an array
  50.  *        of 256-character arrays which are set to C strings.  For
  51.  *        check-boxes, it points to an array of integers set to -1 or 0, 
  52.  *        depending on the final state of the checkboxes.  for ints
  53.  *        floats, and chars, it points to an array of the appropriate
  54.  *        type, which is set to the entered values.
  55.  *    int finit;
  56.  *        A boolean which tells whether the dialog should be set up to
  57.  *        display the original values pointed to by pvalue.  Otherwise
  58.  *        it leaves buttons and check-boxes empty and editable text
  59.  *        null.
  60.  *    int (*pfunc)();
  61.  *        A pointer to a function to be called when one of the items in
  62.  *        the set is modified.  Called as
  63.  *            (*(pedihit->pfunc))(pdi, pedi, pedihit, itemnum)
  64.  *        where pdi is the pointer to the dialog, pedi is a pointer
  65.  *        to the array of EDITEMs, pedihit is a pointer to the
  66.  *        particular EDITEM containing the modified item.  The
  67.  *        itemnum is the dialog item number.  If the function returns
  68.  *        a non-zero value, EasyDialog immediately returns that value.
  69.  *        Otherwise, it continues.
  70.  *
  71.  *    This package desparately needs an example to make itself clear.
  72.  *    The orbit program uses this package for three different dialogs.
  73.  *    Dialogs handlers are ordinarily so tedious to write that this
  74.  *    package paid back the time required to write it in this program
  75.  *    alone.  (At least it was more fun to write :-)
  76.  *    The orbit program, and EasyDialog are bundled together in this
  77.  *    posting.
  78.  */
  79.  
  80.  
  81. #ifndef TRUE
  82. #define TRUE -1
  83. #define FALSE 0
  84. #endif
  85.  
  86. #ifndef NULL
  87. #define NULL (0l)
  88. #endif
  89.  
  90. #define Bool10(f) ((f) ? 1 : 0 )
  91.  
  92. #define MAXEDCCH 256    /* spacing between text strings in array */
  93.  
  94. enum EDItemType {
  95.     edlast,                /* no more items    */
  96.     edbutton,            /* button set */
  97.     edchar,                /* a single character */
  98.     edstring,            /* a string of characters <= 242 characters*/
  99.     edint,                /* a standard length integer */
  100.     edfloat,            /* a double precision floating point number */
  101.     edrad,                /* radio button set */
  102.     edcheck,            /* a check box    */
  103.     edscpair            /* a scroll bar, editable value pair */
  104.                         /* (to be implemented) */
  105. };
  106.  
  107. typedef struct {
  108.     int nitems;                    /* number of items in set                */
  109.     int firstitem;                
  110.     enum EDItemType itemtype;    /* what type of item set                */
  111.     void *pvalue;                /* pointer to first value of right type */
  112.     int finit;                    /* whether to initialize the data        */
  113.     int (*pfunc)();                /* function to execute, called as:        */
  114. } EDITEM;            /*    (*(pedihit->pfunc))(pdi, pedi, pedihit, itemnum)*/
  115.  
  116. /***************** Not yet implemented *****************/
  117. typedef struct {
  118.     int min, max;                /* minimum and maximum values */
  119.     int thumbstep, arrowstep;    /* change in value for thumb or arrow */
  120.     int value;
  121. } EDSCPAIRTYPE;